<?php

/**
 * This is the model class for table "{{activity}}".
 *
 * The followings are the available columns in table '{{activity}}':
 * @property integer $zac_id
 * @property string $zac_title
 * @property integer $zac_type
 * @property integer $zac_pay_type
 * @property integer $zac_start_time
 * @property integer $zac_end_time
 * @property integer $zac_a_time
 * @property integer $zac_e_time
 * @property string $zac_content
 * @property string $zac_pic
 * @property integer $zac_status
 * @property integer $inputtime
 */
class Activity extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Activity the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return '{{activity}}';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('zac_title, zac_start_time, zac_end_time, zac_a_time, zac_e_time', 'required'),
			array('zac_type, zac_pay_type, zac_status, inputtime', 'numerical', 'integerOnly'=>true),
			array('zac_title,zac_start_time, zac_end_time, zac_a_time, zac_e_time', 'length', 'max'=>50),
			array('zac_pic', 'length', 'max'=>255),
			array('zac_content', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('zac_id, zac_title, zac_type, zac_pay_type, zac_start_time, zac_end_time, zac_a_time, zac_e_time, zac_content, zac_pic, zac_status, inputtime', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'zac_id' => '活动',
			'zac_title' => '活动标题',
			'zac_type' => '活动类型',
			'zac_pay_type' => '收费类型',
			'zac_start_time' => '报名开始时间',
			'zac_end_time' => '报名结束时间',
			'zac_a_time' => '活动开始时间',
			'zac_e_time' => '活动结束时间',
			'zac_content' => '活动描述',
			'zac_pic' => '图片',
			'zac_status' => '状态',
			'inputtime' => '创建时间',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('zac_id',$this->zac_id);
		$criteria->compare('zac_title',$this->zac_title,true);
		$criteria->compare('zac_type',$this->zac_type);
		$criteria->compare('zac_pay_type',$this->zac_pay_type);
		$criteria->compare('zac_start_time',$this->zac_start_time);
		$criteria->compare('zac_end_time',$this->zac_end_time);
		$criteria->compare('zac_a_time',$this->zac_a_time);
		$criteria->compare('zac_e_time',$this->zac_e_time);
		$criteria->compare('zac_content',$this->zac_content,true);
		$criteria->compare('zac_pic',$this->zac_pic,true);
		$criteria->compare('zac_status',$this->zac_status);
		$criteria->compare('inputtime',$this->inputtime);

		$criteria->order = " inputtime DESC ";
		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
	
	/**
	 * 保存前的操作，创建活动时取当前时间组创建时间
	 */
	public function beforeSave(){
		if($this->isNewRecord){
			$this->inputtime = time();
		}
		return true;
	}
}